-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow keep_aspect_ratio flag in templates. #1119
Conversation
Add appropriate tests and update documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your PR is really nice!
Could please also add a mention of this addition in CHANGELOG.md
?
@@ -84,6 +84,7 @@ def load_elements(self, elements): | |||
"priority": int, | |||
"multiline": (bool, type(None)), | |||
"rotate": (int, float), | |||
"keep_aspect_ratio": object, # "bool or equivalent", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not typing this as bool
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was mostly just a little confused here with the types, as other fields also seem to be flags but are typed as objects (eg. bold
& italic
). Seems that "multiline" is also possibly a bool but it is typed as (bool, type(None)
) for some reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gmischler just a ping for you on this subject, as you have more experience than me with the templating system 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like I added this in #244.
The motivation was to allow other values with a True/False meaning, similar to what most library functions in Python allow. The documentation also specifies "enabled with True or equivalent value".
If there is a better/more explicit way to specify this, I haven't found it yet...
The other reason was that bold/italic/underline can also be specified in in a csv file, which uses ints instead of bools (more precisely: strings representing ints). This reason does not apply to keep_aspect_ratio
, but the first one still does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright!
So what do you think is the best there? int
? (bool, int)
?
IMHO we could stick to bool
even if non-boolean "truthy" values are also valid, this would make the intent of this parameter clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO we could stick to
bool
even if non-boolean "truthy" values are also valid, this would make the intent of this parameter clearer.
If we use bool
, then we need an additional conversion (first from str
to int
, then to bool
) for CSV files.
You'd expect there to be a standard way of expressing "bool or True/False equivalent", wouldn't you?
A quick search has not turned up anything useful for me...
Maybe just using bool
is really the simplest way, although that is technically a backwards incompatible change.
@@ -190,6 +191,7 @@ def _varsep_float(s, default="0"): | |||
("priority", int, False), | |||
("multiline", self._parse_multiline, False), | |||
("rotate", _varsep_float, False), | |||
("keep_aspect_ratio", int, False), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
("keep_aspect_ratio", int, False), | |
("keep_aspect_ratio", bool, False), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, the converter is int
here in order to maintain similarity to the other boolean flags. Would need to test if this behaviour works (though I cannot see why it shouldn't).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing bold/italic/underline to using bool
would require additional conversion magic when reading CSVs. Since we're evaluating strings there, currently int("0")
evaluates correctly as False
, while bool("0")
would incorrectly evaluate to True
.
It might be helpful to add some comments to the code explaining this...
Of couse, since keep_aspect_ratio
is not supported via CSV, that one can use bool
without a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed!
Do you have enough information in our answers to adress the review feedbacks @Clock-Speed? 🙂 |
@allcontributors please add @Clock-Speed for code |
I've put up a pull request to add @Clock-Speed! 🎉 |
Hi! Just a quick update about this: @Clock-Speed are you still willing to work on this feature? Also, if you need feedback or help on this PR, please tell us! 🙂 |
Closing this PR for now. |
Fixes #1118
Allows for using the keep_aspect_ratio flag from the image method to templates.
Example use:
Which gives the following output:
keep_aspect_ratio=true.pdf
Compared to when
keep_aspect_ratio
is set to False:keep_aspect_ratio=false.pdf
Checklist:
The GitHub pipeline is OK (green),
meaning that both
pylint
(static code analyzer) andblack
(code formatter) are happy with the changes of this PR.A unit test is covering the code added / modified by this PR
This PR is ready to be merged
In case of a new feature, docstrings have been added, with also some documentation in the
docs/
folderA mention of the change is present in
CHANGELOG.md
By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.